package com.wltt.healing.healingusercommon.utils;

import org.springframework.util.StringUtils;

/**
 * @Author: wltt
 * @Date: 2021/11/18 23:14
 * @Version: 1.0
 * @Description: TODO
 */
public abstract class SaltUtil {

    /**
     * 对字符进行加盐
     *
     * @param original 原始字符串
     * @param salt     盐值
     */
    public static String getSaltString(String original, String salt) {
        if (!StringUtils.hasLength(original)) {
            throw new RuntimeException("原始字符串为null");
        }
        if (!StringUtils.hasLength(salt)) {
            throw new RuntimeException("盐值为null");
        }

        int originalLength = original.length();
        int saltLength = salt.length();
        int size = originalLength;
        if (saltLength > originalLength) {
            size = saltLength;
        }

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < size; i++) {
            if (i < originalLength) {
                sb.append(original.charAt(i));
            }
            if (i < saltLength) {
                sb.append(salt.charAt(i));
            }
        }
        return sb.toString();
    }


    public static void main(String[] args) {
        System.out.println(getSaltString("dddd", "ccccc"));
    }
}
